﻿using System;
using System.Collections.Generic;
using System.Data;
using Ue.Infrastructure;
using Ue.Infrastructure.DomainBase;
using Ue.Infrastructure.RepositoryFramework.Repository;
using Ue.Qcdz.Domain.Tags;

namespace Ue.Qcdz.Repositories.Tags
{
    public class TagRepository : SqlServerRepository<Tag>, ITagRepository
    {
        public TagRepository()
            : this(null) { }

        public TagRepository(IUnitOfWork uniteOfWork)
            : base(uniteOfWork) { }



        #region SqlServerRepositoryBase

        protected override string GetDataTableName()
        {
            return "Tags";
        }

        protected override string GetKeyFieldName()
        {
            return "Id";
        }

        protected override string GetOrderBy()
        {
            return string.Empty;
        }

        protected override string[] GetBaseInsertFields()
        {
            return new string[]{
                TagFactory.FieldNames.EntityKey,
                TagFactory.FieldNames.ContentTypeIdInTags,
                TagFactory.FieldNames.TagName,
                TagFactory.FieldNames.Descritpion,
                TagFactory.FieldNames.CreateOn
            };
        }

        protected override string[] GetBaseUpdateFields()
        {
            return new string[]{
                TagFactory.FieldNames.TagName,
                TagFactory.FieldNames.Descritpion
            };
        }

        protected override IDataParameter[] BuildParameters(Tag entity)
        {
            return new IDataParameter[]{
                this.RepositoryDriver.BuildParameter(TagFactory.FieldNames.EntityKey,entity.Key),
                this.RepositoryDriver.BuildParameter(TagFactory.FieldNames.ContentTypeIdInTags,entity.ContentType==null?null:entity.ContentType.Key.ToString()),
                this.RepositoryDriver.BuildParameter(TagFactory.FieldNames.TagName,entity.Name),
                this.RepositoryDriver.BuildParameter(TagFactory.FieldNames.Descritpion,entity.Description),
                this.RepositoryDriver.BuildParameter(TagFactory.FieldNames.CreateOn,entity.CreateOn)
            };
        }

        protected override IWhereClause BuildWhereClauseBy(IDataQuery dataQuery)
        {
            return null; 
        }

        #endregion

        protected override IDictionary<string, SqlServerRepositoryBase<Tag>.ChildDataHandler> GetBuildEntityChildCallbacks()
        {
            return null;
        }
    }
}
